package net.pessu.android.shoppoid.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DatabaseHelper extends SQLiteOpenHelper {

	private static final String TAG = "DatabaseHelper";

	DatabaseHelper(Context context) {
		super(context, ConstantesDatabase.MY_DATABASE_TABLE, null,
				ConstantesDatabase.DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {

		StringBuilder sb = new StringBuilder();
		sb.append(ConstantesDatabase.CREATE_TABLE_IF_NOT_EXISTS);
		sb.append(ConstantesDatabase.MY_DATABASE_TABLE);
		sb.append(ConstantesDatabase.DEF_MA_DATABASE_TABLE);
		db.execSQL(sb.toString());
		sb = new StringBuilder();
		sb.append(ConstantesDatabase.CREATE_TABLE_IF_NOT_EXISTS);
		sb.append(ConstantesDatabase.MY_DATABASE_TABLE2);
		sb.append(ConstantesDatabase.DEF_MA_DATABASE_TABLE2);
		db.execSQL(sb.toString());
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
				+ newVersion + ", which will destroy all old data");


		onCreate(db);
		if (oldVersion == 2) {
			if (newVersion == ConstantesDatabase.DATABASE_VERSION) {
				String queryUpdate = "ALTER table "
						+ ConstantesDatabase.MY_DATABASE_TABLE
						+ " add  prixorigine NUMERIC";
				db.execSQL(queryUpdate);
			}
		}

		
	}
}
